<template>
    <div>
        <n-modal :show-icon="false" v-model:show="showModal" preset="dialog" title="创建" style="width:50%"
            :on-after-leave="handCleas">
            <div class="cotent">
                <div class="myLeave">
                    <n-form ref="formRef" label-placement="left">
                        <n-form-item label="申请人:">
                            <span>{{shoWData.applyUser.userName}}</span>
                        </n-form-item>
                        <n-form-item label="休假类型:">
                            <span>{{ shoWData.applyState == 1
                                    ? '待审批' : shoWData.applyState == 2 ? "审批中" : shoWData.applyState == 3 ? "拒审批拒绝" :
                                        shoWData.applyState == 4 ? '审批通过' : shoWData.applyState == 5 ? '废弃' : '其他'
                            }}</span>
                        </n-form-item>
                        <n-form-item label="休假时间:">
                            <span>{{ shoWData.DateProcess }}</span>
                        </n-form-item>
                        <n-form-item label="休假时长:">
                            <span>{{ shoWData.leaveTime }} 天</span>
                        </n-form-item>
                        <n-form-item label="休假原因:">
                            <span>{{ shoWData.reasons }}</span>
                        </n-form-item>
                        <n-form-item label="审批状态:">
                            <span>{{ shoWData.applyType == 1 ? '事假' : shoWData.applyType == 2 ? '调休' :
                                    shoWData.applyType
                                        == 3 ? '年假' : '其他'
                            }}</span>
                        </n-form-item>
                        <n-form-item label="审批人:">
                            <span>{{ shoWData.auditUsers }}</span>
                        </n-form-item>
                        <n-form-item label="备注:">
                            <n-input type="textarea" v-model:value="params.remak" placeholder="请填写备注" />
                        </n-form-item>
                    </n-form>
                </div>
            </div>

            <template #action>
                <n-space>
                    <n-button @click="approvalMethod('bohui')">驳回</n-button>
                    <n-button type="info" :loading="formBtnLoading" @click="approvalMethod('ok')">审批通过</n-button>
                </n-space>
            </template>
        </n-modal>
    </div>
</template>
<script lang="ts">
import { defineComponent, ref, reactive, toRefs, onMounted, onBeforeMount } from 'vue'
import { leavesApprove } from '../../../../api/leaves'
import { useMessage } from 'naive-ui'
// @ts-ignore
const message = useMessage()
export default {
    setup(props,{emit}) {
        const showModal = ref(false)
        const state = reactive({
            current: 1,
            currentStatus: null,
            shoWData: {},
            params: {
                remak: '',
                _id: '',
                action: ''
            }
        })
        const methods = reactive({
            // 取消
            approvalMethod(item) {
                if (item == 'bohui') { //驳回
                    state.params.action = 'refuse'
                    leavesApprove(state.params).then(res=>{
                       showModal.value = false
                         this.params={}
                         message.success('处理成功')
                         emit('getMessage','')
                    })
                }
                if (item == 'ok') { //通过
                     state.params.action ='ok'
                     leavesApprove(state.params).then(res=>{
                        showModal.value = false
                        this.params={}
                        message.success('处理成功')
                        emit('getMessage','')
                    })
                }
            },

            showModalfun(item) {
                showModal.value = true
                state.shoWData = item
                state.params._id = item._id
            },
            handCleas() {
                showModal.value = false

            }

        })

        return {
            ...toRefs(methods),
            showModal,
            ...toRefs(state)
        }
    }
}

</script>

<style lang="scss">
.myLeave {
    padding: 20px 0;
}

.myLeave .n-form-item-feedback-wrapper {
    min-height: 10px !important;
}
</style>